package sk.tramtatiri;

import java.awt.image.BufferedImage;

import org.apache.wicket.markup.html.image.NonCachingImage;
import org.apache.wicket.markup.html.image.resource.DynamicImageResource;

import com.octo.captcha.service.image.ImageCaptchaService;

/**
 * class for generating captcha image for registration class
 * @author huonator
 */
public abstract class CaptchaImage extends NonCachingImage {
	  private static final long serialVersionUID = 4905058173942091881L;

          /**
           * Constructor of class CaptchaImage for generating captcha image for registration class
           * @param id
           * @param challengeId
           */
	  public CaptchaImage(String id, final String challengeId) {
	    super(id);
	    setImageResource(new DynamicImageResource("jpeg") {
	      private static final long serialVersionUID = 4196141161969994290L;

	      @Override
	      protected byte[] getImageData() {
	        BufferedImage image = getImageCaptchaService().getImageChallengeForID(challengeId, CaptchaImage.this.getLocale());
	        return toImageData(image);
	      }
	    });
	  }

          /**
           * Abstract method represents getter for captcha image service
           * @return captchService
           */
	  protected abstract ImageCaptchaService getImageCaptchaService();
	}